package Avocado.form {

	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;

	public class FormTitulo extends Sprite {
		
		private var titulo:String;
		private var tituloWidth:Number;
		
		private var background:Sprite;
		
		private var format:TextFormat;
		private var field:TextField;

		public function FormTitulo(_format:TextFormat, _titulo:String='Title', _tituloWidth:Number=100) {
			super();
			this.format = _format;
			this.titulo = _titulo;
			this.tituloWidth = _tituloWidth;
			this.addEventListener(Event.ADDED_TO_STAGE, initThis);
		}
		
		private function initThis(e:Event):void{
			this.removeEventListener(Event.ADDED_TO_STAGE, initThis);
			
			setupBackground();
			setupField();
		}
		
		private function setupBackground():void{
			background = new Sprite;
			background.graphics.beginFill(0x537f17);
			background.graphics.drawRect(0,0,tituloWidth,41);
			background.graphics.endFill();
			addChild(background);
		}

		private function setupField():void{
			format.letterSpacing = -0.8;

			field = new TextField;
			field.text = titulo;
			field.embedFonts = true;
			field.autoSize = TextFieldAutoSize.LEFT;
			field.setTextFormat(format);
			field.x = 12;
			field.y = 6;
			addChild(field);
		}
		
	}
}
